import java.io.File;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;

import util.IO;

/**
 * Init 用于根据名单创建存放学生作业的目录
 */
public class Init {
    /**
     * 将名单中的行转化成文件夹名称
     * 
     * @param lineList
     * @return
     */
    private static List<String> getDirList(List<String> lineList) {
        List<String> dirList = new ArrayList<>();
        //遍历lineList并将非id开头的字符串中","替换为“-”，存入List<String>类型后返回
        for (String line : lineList) {
            if (line.startsWith("id")) {
                continue;
            }
            String dir = line.replace(",", "-");
            dirList.add(dir);
        }
        return dirList;
    }

    public static void run(String nameListFile, String hwDir) {
        IO.mkdir(hwDir);
        List<String> lineList = IO.fileToStringList(nameListFile, StandardCharsets.UTF_8);
        List<String> dirList = getDirList(lineList);
        for (String dir : dirList) {
            String newDir = hwDir + File.separator + dir;
            IO.mkdir(newDir);
        }
    }

    public static void main(String[] args) {
        // 测试
        // javac -cp src/ -d dist/ src/Init.java
        // java -cp dist/ Init name-list.csv hw
        String nameListFile = args[0];  //nameListFile = "name-list.csv";
        String hwDir = args[1];         //hwDir = "hw";
        Init.run(nameListFile, hwDir);
    }
}